<template>
  <section>
    <el-button
      v-permission="installPermissions.permissions.group.edit"
      @click="handleEdit(row)"
      type="text"
      size="small"
    >
      编辑
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.group.edit"
      @click="chooseCooperative(row)"
      type="text"
      size="small"
    >
      选择合作社
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.group.edit"
      @click="chooseEmployee(row)"
      type="text"
      size="small"
    >
      选择员工
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.group.del"
      @click="handleDelete(row)"
      type="text"
      size="small"
    >
      删除
    </el-button>
    <!--<el-dropdown-item-->
    <!--command="delete">删除用户</el-dropdown-item>-->
    <!--<el-dropdown-item
              v-permission="'user.status.control'"
              command="status">{{ row.status.value == "EFFECTIVED" ? "禁用" : "激活" }}用户</el-dropdown-item>-->
    <!--</el-dropdown-menu>-->
    <!--</el-dropdown>-->
  </section>
</template>
<style>
</style>
<script>
    export default {
        props: {
            row: {
                type: Object,
                default: function () {
                    return {};
                }
            },
            col: {
                type: Object,
                default: function () {
                    return {};
                }
            }
        },
        methods: {
            handleStatus() {
                let ops = this.row.status.value == "EFFECTIVED" ? "禁用" : "激活";
                let status =
                    this.row.status.value == "EFFECTIVED" ? "INVALID" : "EFFECTIVED";
                this.$confirm("此操作将" + ops + "该用户, 是否继续?", ops + "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api.user.status(this.row.id, status, () => {
                        this.$message({
                            type: "success",
                            message: ops + "用户成功",
                            onClose: this.$emit("deleteDone", this.row)
                        });
                    });
                });
            },
            handleDelete() {
                this.$confirm("此操作将删除该分组, 是否继续?", "删除提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api.group.delete(this.row.id, () => {
                        this.$message({
                            type: "success",
                            message: "删除分组成功",
                            onClose: () => {
                                this.$emit("deleteDone", this.row);
                            }
                        });
                    });
                });
            },
            handleReset() {
                this.$confirm("此操作将重置该用户密码, 是否继续?", "重置密码提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api.user.reset(this.row.id, () => {
                        this.$message({
                            type: "success",
                            message: "重置密码成功",
                            onClose: () => {
                                this.$emit("deleteDone", this.row);
                            }
                        });
                    });
                });
            },
            handleEdit() {
                this.$emit("editRow", this.row);
            },
            chooseCooperative() {
                this.$emit("chooseCooperative", this.row);
            },
            chooseEmployee() {
                this.$emit("chooseEmployee", this.row);
            }
        }
    };
</script>
